const { validate, validations } = require('ws-chat-common').validate
const respont = require('ws-chat-common').respond
const db = uniCloud.database()
module.exports = {
  get: async function (e) {
    const id = validate(validations.notice.needId, e)
    return db.collection('notice').doc(id).get()
  },
  add: async function (e = {}) {
    return db.collection('notice').add(e)
  },
  del: async function (id) {
    return db.collection('notice').doc(id).remove()
  },
  update: async function (e) {
    return db.collection('notice').doc(e.id).update(e)
  },
  getList: async function (e = {}) {
    e.pageNum = e.pageNum || 1
    e.pageSize = e.pageSize || 100
    const { data } = await db
      .collection('notice')
      .skip(e.pageSize * (e.pageNum - 1))
      .limit(e.pageSize)
      .get()
    return data
  },
  _after: respont.afterHandle,
}
